package ui;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
import java.io.File;
import java.util.ArrayList;

import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JSeparator;

import org.lwjgl.LWJGLException;

import primatives.PointND;
import util.PointCloudReader;

public class Window_STLMesh extends JFrame
{
	public STLCanvas canvas;
	public JMenuBar menu_bar;
	public JMenu menu_file;
	
	public Window_STLMesh(String s, int w, int h) throws LWJGLException
	{
		setTitle(s);
		setSize(w, h);
		setLayout(new BorderLayout(5, 5));
		
		// setup OpenGL canvas
		add(canvas = new STLCanvas(), BorderLayout.CENTER);
		canvas.addKeyListener(new KeyListener() {
			
			@Override
			public void keyTyped(KeyEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void keyReleased(KeyEvent e) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void keyPressed(KeyEvent e)
			{
				canvas.move_mesh(e);
			}
		});
		
		setupGUI();
		
		setResizable(false);
		setVisible(true);
		setDefaultCloseOperation(DISPOSE_ON_CLOSE);
	}
	
	public void setupGUI()
	{
		JMenuItem fileOpen = new JMenuItem("Open");
		fileOpen.addActionListener(new ActionListener()
		{
	        public void actionPerformed(ActionEvent e)
	        {
	        	canvas.mesh.load();
	        }
		});
		
		JMenuItem fileClose = new JMenuItem("Exit");
		fileClose.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event)  { System.exit(0); } });
		
		menu_file = new JMenu("File");
		menu_file.add(fileOpen);
		menu_file.add(new JSeparator());
		menu_file.add(fileClose);
		
		menu_bar = new JMenuBar();
		menu_bar.add(menu_file);
		setJMenuBar(menu_bar);
	}
	
	public static void main(String[] args) throws LWJGLException
	{
		Window_STLMesh frame = new Window_STLMesh("STL Mesh Viewer", UIConst.APP_WIDTH, UIConst.APP_HEIGHT);
	}
}
